package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

class zaun {
   ArrayList a;
   boolean[] b;
   boolean[] c;
   zauk d;

   zaun(zauk var1) {
      this.d = var1;
   }

   zaun(zauk var1, int var2, int var3) {
      this.d = var1;
      this.a = new ArrayList(var2);
      this.b = new boolean[var3];

      for(int var4 = 0; var4 < var2; ++var4) {
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new Object[var3]));
      }

   }

   void a() {
      boolean var1 = false;
      int var4;
      if (this.d.m != 0) {
         var4 = Math.min(this.d.k, this.d.m);
      } else {
         var4 = this.d.k;
      }

      int var2;
      if (this.d.e != null && this.d.e.length == 1 && null != this.d.e[0].b) {
         var2 = this.d.e[0].b.getRowCount() - 1;
         if (var2 <= this.d.k && var2 <= this.d.e[0].b.a.getMaxDataRow()) {
            var4 = var2;
         }
      }

      this.a = new ArrayList(var4);

      for(var2 = 0; var2 < var4; ++var2) {
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)(new Object[this.d.i]));
      }

      this.b = new boolean[this.d.i];
      this.c = new boolean[this.d.i];

      for(var2 = 0; var2 < this.d.p.size(); ++var2) {
         zbqs var3 = (zbqs)this.d.p.get(var2);
         if (!var3.m() && var2 < this.b.length) {
            this.b[var2] = var3.c();
            this.c[var2] = var3.d();
         }
      }

   }

   void a(zbqs var1) {
      int[] var2 = new int[this.d.k];
      int var3 = var1.w();
      if (this.b != null && !this.b[var3]) {
         ArrayList var4 = new ArrayList();
         HashMap var5 = new HashMap();
         int var6 = -1;
         int var7 = 0;
         boolean var8 = false;
         boolean var9 = false;

         int var10;
         for(var10 = 0; var10 < this.a.size(); ++var10) {
            Object var11 = ((Object[])((Object[])this.a.get(var10)))[var3];
            if (var11 == null) {
               if (var6 == -1) {
                  var6 = var7++;
                  zbmb var12 = new zbmb();
                  var12.a = null;
                  com.aspose.cells.b.a.a.ze.a(var4, (Object)var12);
               }

               if (var10 < var2.length) {
                  var2[var10] = var6;
               }
            } else {
               boolean[] var16 = new boolean[]{var8};
               boolean[] var13 = new boolean[]{var9};
               var11 = zauk.a(var11, var1, var16, var13);
               var8 = var16[0];
               var9 = var13[0];
               zbmb var14;
               if (var11 == null) {
                  if (var6 == -1) {
                     var6 = var7++;
                     var14 = new zbmb();
                     var14.a = null;
                     com.aspose.cells.b.a.a.ze.a(var4, (Object)var14);
                  }

                  if (var10 < var2.length) {
                     var2[var10] = var6;
                  }
               } else {
                  var14 = null;
                  Object var17;
                  if (var8) {
                     var17 = var5.get(((String)var11).toUpperCase());
                  } else if (var9) {
                     var17 = var5.get(com.aspose.cells.b.a.zr.a(var11).toUpperCase());
                  } else {
                     var17 = var5.get(var11);
                  }

                  if (var17 == null) {
                     if (var10 < var2.length) {
                        var2[var10] = var7;
                     }

                     if (var8) {
                        var5.put(((String)var11).toUpperCase(), var7++);
                     } else if (var9) {
                        var5.put(com.aspose.cells.b.a.zr.a(var11).toUpperCase(), var7++);
                     } else {
                        var5.put(var11, var7++);
                     }

                     zbmb var15 = new zbmb();
                     var15.a = var11;
                     com.aspose.cells.b.a.a.ze.a(var4, (Object)var15);
                  } else if (var10 < var2.length) {
                     var2[var10] = (Integer)var17;
                  }
               }
            }
         }

         if (var4.size() >= 32767) {
            var1.i(true);
            var1.c = null;
         } else {
            var1.c = var4;
            var1.a(true);
            if (var2.length > 0) {
               this.b[var3] = true;

               for(var10 = 0; var10 < this.a.size(); ++var10) {
                  if (var10 < var2.length) {
                     ((Object[])((Object[])this.a.get(var10)))[var3] = var2[var10];
                  }
               }
            }

         }
      }
   }

   int b() {
      int var1 = 0;

      for(int var2 = 0; var2 < this.b.length; ++var2) {
         if (this.b[var2]) {
            ++var1;
         }
      }

      return var1;
   }

   void a(zqa var1) throws Exception {
      int var2 = this.b();
      boolean var3 = var2 >= 256;
      if (!var3) {
         for(int var4 = 0; var4 < this.d.p.size(); ++var4) {
            zbqs var5 = (zbqs)this.d.p.get(var4);
            if (var5.c != null && var5.c.size() >= 256 && var5.j == null) {
               var3 = true;
               break;
            }
         }
      }

      Object var12 = null;
      byte[] var13;
      if (var3) {
         var13 = new byte[4 + var2 * 2];
         System.arraycopy(com.aspose.cells.b.a.zc.a(var2 * 2), 0, var13, 2, 2);
      } else {
         var13 = new byte[4 + var2];
         var13[2] = (byte)var2;
      }

      var13[0] = -56;
      byte[] var14 = null;
      boolean var6 = false;
      boolean var7 = false;

      for(int var8 = 0; var8 < this.a.size(); ++var8) {
         Object[] var9 = (Object[])((Object[])this.a.get(var8));
         int var16 = 0;
         int var15 = 0;

         int var10;
         Class var11;
         for(var10 = 0; var10 < var9.length; ++var10) {
            if (this.b[var10]) {
               if (var9[var10] != null) {
                  if (var3) {
                     System.arraycopy(com.aspose.cells.b.a.zc.a((Integer)var9[var10]), 0, var13, 4 + var15 * 2, 2);
                  } else {
                     var13[4 + var15] = (byte)com.aspose.cells.b.a.ze.f(var9[var10]);
                  }

                  ++var15;
               }
            } else if (var9[var10] == null) {
               var16 += 4;
            } else {
               var11 = var9[var10].getClass();
               switch(zamo.a(var11)) {
               case 3:
                  var16 += 6;
                  break;
               case 9:
               case 14:
               case 16:
                  var16 += 12;
                  break;
               case 18:
                  var16 += 6 + zakq.e((String)var9[var10]);
               }
            }
         }

         var1.a(var13);
         if (var14 == null || var14.length < var16) {
            var14 = new byte[var16];
         }

         var15 = 0;

         for(var10 = 0; var10 < var9.length; ++var10) {
            if (!this.b[var10]) {
               if (var9[var10] == null) {
                  var15 += zbqs.a(var14, var15);
               } else {
                  var11 = var9[var10].getClass();
                  switch(zamo.a(var11)) {
                  case 3:
                     var15 += zbqs.a(var14, var15, (Boolean)var9[var10]);
                     break;
                  case 9:
                     var15 += zbqs.a(var14, var15, (double)(Integer)var9[var10]);
                     break;
                  case 14:
                     var15 += zbqs.a(var14, var15, (Double)var9[var10]);
                     break;
                  case 16:
                     var15 += zbqs.a(var14, var15, (DateTime)var9[var10]);
                     break;
                  case 18:
                     var15 += zbqs.a(var14, var15, (String)var9[var10]);
                  }
               }
            }
         }

         var1.a(var14, var16);
      }

   }
}
